#include"led.h"


void LED_init(void)
{
    RCC->APB2ENR|=RCC_APB2ENR_IOPAEN;

    GPIOA->CRL &= ~GPIO_CRL_CNF0;
    GPIOA->CRL |= GPIO_CRL_MODE0;

    GPIOA->CRL &= ~GPIO_CRL_CNF1;
    GPIOA->CRL |= GPIO_CRL_MODE1;

    GPIOA->CRH &= ~GPIO_CRH_CNF8;
    GPIOA->CRH |= GPIO_CRH_MODE8;
    LED_Off(LED1);
    LED_Off(LED2);
    LED_Off(LED3);
}

void LED_On(uint16_t led)
{
    GPIOA->ODR &=~ led;
}

void LED_Off(uint16_t led)
{
    GPIOA->ODR|=led;
}

void LED_Toggle(uint16_t led)
{
    if(GPIOA->IDR & led==0)                      //接收到寄存器的状态
    {
        LED_Off(led);
    }                
    else{
        LED_On(led);
    }    
}

void LED_Onall(uint16_t led[],int8_t count)
{
    for(int i=0;i<count;i++)
    {
        LED_On(led[i]);
    }
}

void LED_Offall(uint16_t led[],int8_t count)
{
    for(int i=0;i<count;i++)
    {
        LED_Off(led[i]);
    }
}
